package com.example.controller.flowable.adm;

import com.example.pojo.GsPy;
import com.example.service.flowable.adm.IGsPyService;
import com.example.service.flowable.adm.impl.GsPyServiceImpl;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

/**
 * <p>
 * 物品申请表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-04-11
 */
@RestController
@RequestMapping("/process/gs-py")
@Api(tags = "物品申请表",value = "")
@CrossOrigin(allowCredentials = "true")
public class GsPyController {

    @Autowired
    private IGsPyService gsPyService;

    @PostMapping("/create")
    @ApiOperation(value = "新建申请")
    public ResultVo createGsPy(@RequestBody  GsPy gsPy){
        return gsPyService.createGsPy(gsPy);
    }

    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有物品申请")
    public PageInfo<GsPy> getAllGsPy(Integer empId,Integer deptId,
                                     @RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "2") Integer pageSize){
        return gsPyService.getAllGsPy(empId,deptId,pageNum,pageSize);
    }

    @ApiOperation(value = "修改申请信息状态")
    @PutMapping("/update")
    public ResultVo updateStatus(@RequestBody GsPy gsPy){
        if (gsPyService.updateById(gsPy)) {
            return ResultVo.success("修改成功。");
        }
        return ResultVo.error("修改失败!");
    }

//    @GetMapping("/query")
//    @ApiOperation(value = "")
//    public ResultVo queryGsPyList(){
//        return gsPyService.queryGsPyList();
//    }
//
//    @PostMapping("/add")
//    @ApiOperation(value = "发起一个物品领用申请")
//    public ResultVo addGsPy(@RequestBody GsPy gsPy){
//        return gsPyService.addGsPy(gsPy);
//    }
//
    @ApiOperation(value = "查询领用之后的个人资产")
    @GetMapping("/Mygoods")
    public ResultVo selectMyGsPt(Integer userId,String name){
        return gsPyService.selectMyGsPt(userId,name);
    }

    @ApiOperation(value = "审批")
    @PutMapping("/audit-task")
    public ResultVo auditTask(@RequestParam("gyId")Integer gsId,@RequestParam("approved")Boolean approved){
        return gsPyService.auditTask(gsId,approved);
    }
}
